package com.ask.forMe.service.impl;

import com.ask.forMe.model.entity.Score;
import com.ask.forMe.mapper.ScoreMapper;
import com.ask.forMe.service.ScoreService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ScoreServiceImpl extends ServiceImpl<ScoreMapper, Score> implements ScoreService {
    @Autowired
    private ScoreMapper scoreMapper;

    /**
     * 新增或跟新评分
     *
     * @param userId
     * @param itemId
     * @param score
     * @return
     */
    @Override
    public void addOrUpdateScore(Long userId, Long itemId, Double score, int type) {
        if (type == 1) {
            Score sco = new Score();
            sco.setUserId(userId);
            sco.setItemId(itemId);
            sco.setScore(score);
            save(sco);
        } else
            scoreMapper.updateByUserItemId(userId, itemId, score);
    }
}
